<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Bootstrap Material Admin</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <link rel="stylesheet" href="./css/toastr.min.css">
    <link rel="stylesheet" href="./css/index.css">
    <script src="./js/jquery-3.4.1.min.js"></script>
    <script src="./js/toastr.min.js"></script>
</head>

<body>
    <div class="page login-page">
        <div class="container d-flex align-items-center">
            <div class="form-holder has-shadow">
                <div class="row">
                    <!-- Logo & Information Panel-->
                    <div class="col-lg-6">
                        <div class="info d-flex align-items-center">
                            <div class="content">
                                <div class="logo">
                                    <h1>欢迎登录</h1>
                                </div>
                                <p>itany课程视频管理</p>
                            </div>
                        </div>
                    </div>
                    <!-- Form Panel    -->
                    <div class="col-lg-6 bg-white">
                        <div class="form d-flex align-items-center">
                            <div class="content">
                                <form method="get" action="./home.html" class="form-validate" id="loginFrom">
                                    <div class="form-group">
                                        <input id="login-username" type="text" name="loginName" required
                                            data-msg="请输入用户名" placeholder="用户名" value="admin" class="input-material">
                                    </div>
                                    <div class="form-group">
                                        <input id="login-password" type="password" name="pwd" required
                                            data-msg="请输入密码" placeholder="密码" class="input-material">
                                    </div>
                                    <button id="login" type="button" onclick="doLogin()" class="btn btn-primary">登录</button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        function doLogin() {
            // TODO: 数据格式处理

            let form = $("#loginFrom").serializeArray();
            $.ajax({
                url: 'http://localhost/videoCourse_stu/server/selectTeacherByUsernameAndPwd.php',
                type: 'post',
                data: form,
                dataType: 'json',
                success: (result) => {
                    console.log('result:', result);
                    // alert(result.msg);

                    // toastr.info(result.msg);
                    // toastr.warning(result.msg);
                    
                    if(result.success){
                        toastr.success(result.msg);
                        setTimeout(()=>{
                            // 跳转首页
                            location.href = "./home.html";
                        }, 1000);
                        
                    } else {
                        toastr.error(result.msg);
                    }
                },
                error: function(){
                    alert('请求发送或响应异常');
                }
            });
        }

        var namesArr = [
            "谭京辰","姚安康","吴昊天","宋健",
            "陈思羽","马响","金阿卫","邹晨",
            "李思远","孙楠楠","陈睿","朱进鹏",
            "孔令云"
        ];
        console.log("namesArr:", namesArr);
        

    </script>

</body>

</html>